﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBLib;


namespace LiveCS.Manager
{
    public static class ConfigManager
    {
        #region 变量

        public static object helper = new object();

        #endregion

        #region 常量

        private const string DEFAULT = "LiveCS";

        #endregion

        #region 属性

        private static AdoDataLoader dataLoader;
        /// <summary>
        /// AdoDataLoader，只有Get方法
        /// </summary>
        public static AdoDataLoader DataLoader
        {
            get
            {
                if (dataLoader == null)
                {
                    lock (helper)
                    {
                        if (null == dataLoader)
                        {
                            if (string.IsNullOrEmpty(ConfigManager.ConnectionString)) // 为空，抛异常
                                throw new ArgumentNullException();

                            dataLoader = new AdoDataLoader(ConnectionString, DatabaseType.MDB);
                        }
                    }
                }
                return ConfigManager.dataLoader;
            }
        }

        /// <summary>
        /// 连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                return System.Configuration.ConfigurationManager.ConnectionStrings[DEFAULT].ToString();
            }
        }

        #endregion
    }
}
